<template>
  <div class="app-container">
    <el-tabs type="card" @tab-click="handleClick" v-model="activeName">
      <el-tab-pane label="任务地图" name="first">
        <AssessMap v-if="completeRefreshAssess" :allListData="allListData" :isSaveMapPolygon="isSaveMapPolygon"
          :districtTreeList="districtTreeList" :taskRegionResultNameCodeList="taskRegionResultNameCodeList"
          :importShpTxtWkt="importShpTxtWkt" @xzqhSelect="xzqhSelect" @mapNewTask="mapNewTask" @mapUpdTask="mapUpdTask"
          @mapDelTask="mapDelTask" @mapLoading="mapLoading" @mapShowTask="mapShowTask"
          @queryTaskRegionNameCodeListByGeomText="queryTaskRegionNameCodeListByGeomText"
          @importShpTxt="showHideUploadDiv(true)"></AssessMap>
        <!--上传面板-->
        <div v-if="showHideUploadDivBool" class="new-uploadDiv">
          <div class="new-uploadDiv-inner">
            <span style="position: relative;top: -2px;font-size: 14px;">导入文件类型：</span>
            <el-radio-group v-model="uploadType" @change="changeUploadType">
              <el-radio label="0">shp</el-radio>
              <el-radio label="1">txt</el-radio>
            </el-radio-group>
            <div class="new-fileBtn">
              <template v-if="uploadType == '0'">
                <input type="file" @change="uploadFileChange" style="width: 70px;" id="sceneexamine-button-selectfile-shp"
                  multiple="multiple" accept=".shp,.dbf,.prj,.sbn,.sbx,.shp.xml,.shx,.cpg" />
              </template>
              <template v-if="uploadType == '1'">
                <input type="file" @change="uploadFileChange" style="width: 70px;" id="sceneexamine-button-selectfile-txt"
                  multiple="multiple" accept=".txt" />
              </template>
            </div>
            <div class="new-fieldInfoBtn" v-if="uploadType == '1'">
              <a @click="importTemplate('导入工作区域经纬度模板.txt')">
                <h5>下载模板</h5>
              </a>
            </div>
            <div class="new-filesTextArea">
              <template v-if="uploadType == '0'">
                <el-input type="textarea" :rows="5" placeholder="导入多个文件时，文件名须相同；至少需要导入1个.shp文件和1个.prj文件"
                  v-model="textarea" readonly></el-input>
              </template>
              <template v-else>
                <el-input type="textarea" :rows="5"
                  placeholder="导入1个.txt文件，内容包括可组成1个面的多个点的经纬度数据，具体格式请参照下载模板内容（即经度和纬度用制表符间隔）" v-model="textarea"
                  readonly></el-input>
              </template>
            </div>
            <div class="new-uploadBtnDiv">
              <el-button @click="uploadFileClick" type="primary">上传</el-button>
            </div>
            <div class="new-closeBtnDiv">
              <el-button plain @click="showHideUploadDiv(false)">关闭</el-button>
            </div>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="任务列表" name="second">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="100px">
          <el-form-item label="任务编号" prop="taskNum">
            <el-input placeholder="请输入任务编号" v-model="queryParams.taskNum" clearable @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="任务名称" prop="taskName">
            <el-input v-model="queryParams.taskName" placeholder="请输入任务名称" clearable @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="任务状态" prop="taskStatus">
            <el-select v-model="queryParams.taskStatus" placeholder="请选择状态" clearable @keyup.enter="handleQuery">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="省" prop="province">
            <el-select v-model="queryParams.province" placeholder="请选择省" @change="chooseProvince" clearable
              value-key="id">
              <el-option v-for="item in provinceData" :key="item.id" :label="item.name" :value="item">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="市" prop="city">
            <el-select v-model="queryParams.city" placeholder="请选择市" @change="chooseCity" clearable value-key="id">
              <el-option v-for="item in cityData" :key="item.id" :label="item.name" :value="item">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="区/县" prop="county">
            <el-select v-model="queryParams.county" placeholder="请选择县" @change="chooseCounty" clearable value-key="id">
              <el-option v-for="item in areaData" :key="item.id" :label="item.name" :value="item">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleQuery">查询</el-button>
            <el-button plain @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button plain icon="Delete" :disabled="multiple" @click="handleDelete">删除</el-button>
          </el-col>
        </el-row>
        <!-- container表格区域 -->
        <el-table :data="listData" v-loading="loading" row-key="id" ref="tableRef" stripe
          @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
          <el-table-column label="任务编号" align="center" prop="taskNum" />
          <el-table-column label="任务名称" align="center" prop="taskName">
            <template #default="scope">
              <span @click="handleDetil(scope.row.id)" style="color: var(--el-color-primary);cursor: pointer">{{
                scope.row.taskName
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="任务管理员" align="center" prop="taskManager" />
          <el-table-column label="任务状态" align="center" prop="taskStatus">
            <template #default="scope">
              <div v-if="scope.row.taskStatus == 0">未分配</div>
              <div v-else-if="scope.row.taskStatus == 1">进行中</div>
              <div v-else-if="scope.row.taskStatus == 2">审核中</div>
              <div v-else="scope.row.taskStatus == 3">已结束</div>
            </template>
          </el-table-column>
          <el-table-column label="承担小组" align="center" prop="groupName" />
          <el-table-column label="组长" align="center" prop="groupLeader" />
          <el-table-column label="任务地区" align="center" prop="taskDistrict" show-overflow-tooltip />
          <el-table-column label="所属父任务" align="center" prop="parentTask">
            <template #default="scope">
              <div v-if="scope.row.parentId == 0"></div>
              <div v-else>{{ scope.row.parentTask }}</div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200px" class-name="small-padding fixed-width">
            <template #default="scope">
              <template v-if="scope.row.taskStatus != '2' || scope.row.taskStatus != '3'">
                <template v-if="scope.row.parentId == 0">
                  <el-button type="text" @click="updateParentHandle(scope.row)">修改</el-button>
                </template>
                <template v-else>
                  <el-button type="text" @click="updateSubHandle(scope.row)">修改</el-button>
                </template>
                <el-button type="text" @click="addSub(scope.row)"
                  v-if="!scope.row.groupId && scope.row.parentId == 0 && getProvinceCodeByAllName(scope.row.taskDistrict).length > 1 && scope.row.children.length < getProvinceCodeByAllName(scope.row.taskDistrict).length">新建子任务</el-button>
                <template v-if="scope.row.children.length == 0 && !scope.row.groupId">
                  <el-button type="text" @click="fenPei(scope.row)">分配</el-button>
                </template>
                <el-button type="text" @click="relationHandle(scope.row)"
                  v-if="scope.row.children.length == 0">关联抽样调查点</el-button>
              </template>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
          @pagination="getList" />
      </el-tab-pane>
    </el-tabs>
    <!--新建/修改任务的弹出框 -->
    <el-dialog v-model="openAdd" :title="title" width="800px" append-to-body>
      <p class="dialogTitle">{{ title }}</p>
      <table class="addTask">
        <div v-if="title != '修改任务'">
          <el-form :model="queryParamsAdd" :rules="rules" ref="rulesFormAdd" :inline="true" label-width="140px">
            <el-form-item label="任务年份：" prop="taskYear">
              <el-select placeholder="请选择年份" v-model="queryParamsAdd.taskYear" clearable @change="changeYear">
                <el-option v-for="item in optionsYear" :key="item.id" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <span class="label">任务编号：</span><span>{{ queryParamsAdd.taskNum }}</span>
            </el-form-item>
            <el-form-item label="任务名称：" prop="taskName" style="width: 90%">
              <el-input placeholder="请输入任务名称" clearable v-model="queryParamsAdd.taskName" />
            </el-form-item>
          </el-form>
        </div>
        <tr v-if="title == '修改任务'">
          <td>
            <span class="label">任务年份：</span><span>{{ queryParamsAdd.taskYear }}</span>
          </td>
          <td>
            <span class="label">任务编号：</span><span>{{ queryParamsAdd.taskNum }}</span>
          </td>
        </tr>
        <tr v-if="title == '修改任务'">
          <td colspan="2">
            <el-form :model="queryParamsAdd" :rules="rules" ref="rulesFormAdd" :inline="true" label-width="140px">
              <el-form-item label="任务名称：" prop="taskName" style="width: 90%">
                <el-input placeholder="请输入任务名称" clearable v-model="queryParamsAdd.taskName" />
              </el-form-item>
            </el-form>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <span class="label">面积（平方公里）：</span><span>{{ queryParamsAdd.taskArea }}</span>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <span class="label">任务区域：</span><span class="init-taskDivSpan">{{ queryParamsAdd.taskRegion.substr(0, 358)
            }}</span>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <span class="label">任务地区：</span>
            <span class="init-taskDivSpan" v-if="title == '新建任务'">{{ taskDistrictName }}</span>
            <span class="init-taskDivSpan" v-else>{{ queryParamsAdd.taskDistrict }}</span>
          </td>
        </tr>
        <tr v-if="queryParamsAdd.groupName != ''">
          <td colspan="2">
            <span class="label">承担小组：</span><span>{{ queryParamsAdd.groupName }}</span>
            <el-button plain style="margin-left:20px" @click="fenPeiAdd">修改分配</el-button>
          </td>
        </tr>
      </table>
      <div v-if="title == '新建任务' && subTaskData.length > 0">
        <h3>子任务列表</h3>
        <div class="wrapBox" style="width: 100%">
          <el-table v-loading="loading1" :data="subTaskData" stripe>
            <el-table-column prop="taskNum" align="center" label="子任务编号" show-overflow-tooltip />
            <el-table-column prop="taskName" align="center" label="子任务名称" show-overflow-tooltip />
            <el-table-column prop="taskDistrict" align="center" label="所在省" show-overflow-tooltip />
            <el-table-column prop="groupName" align="center" label="承担小组" show-overflow-tooltip />
            <el-table-column prop="operation" label="操作" align="center">
              <template #default="scope">
                <template v-if="!scope.row.groupId">
                  <el-button type="text" @click="fenPei(scope.row)">分配</el-button>
                </template>
                <el-button type="text" @click="updateSubHandle(scope.row)">修改</el-button>
                <el-button type="text" @click="delSubTask(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- <pagination
            v-show="total1 > 0"
            :total="total1"
            v-model:page="subDataPage.page"
            v-model:limit="subDataPage.rows"
            @pagination="getSubList"
          /> -->
        </div>
      </div>
      <template #footer>
        <span class="dialog-footer" style="text-align: center!important">
          <template v-if="title == '新建任务' && queryParamsAdd.groupName == ''">
            <el-button type="primary" @click="addSub2(queryParamsAdd)"
              v-if="getProvinceCodeByAllName(taskDistrictName.replace(/,/g, '、')).length > 1 && subTaskData.length != getProvinceCodeByAllName(taskDistrictName.replace(/,/g, '、')).length">新建子任务</el-button>
          </template>
          <template v-if="subTaskData.length == 0 &&
            title == '新建任务' &&
            queryParamsAdd.groupName == ''
            ">
            <el-button type="primary" @click="fenPeiAdd()">分配小组</el-button>
          </template>
          <template v-if="subTaskData.length == 0">
            <el-button type="primary" @click="okAdd">保 存</el-button>
          </template>
          <template v-else>
            <el-button type="primary" @click="closeAdd">保 存</el-button>
          </template>
          <template v-if="subTaskData.length == 0">
            <el-button plain @click="cancelAdd">取 消</el-button>
          </template>
        </span>
      </template>
    </el-dialog>
    <!--新建/修改子任务的弹出框 -->
    <el-dialog v-model="openAddSub" :title="titleSub" width="900px" append-to-body v-if="openAddSub">
      <p class="dialogTitle">{{ titleSub }}</p>
      <table class="addSubTask">
        <tr>
          <td><span class="label">子任务编号：</span><span>{{ queryParamsSubAdd.taskNum }}</span></td>
          <td v-if="titleSub == '修改子任务'"><span class="label">所属父任务：</span><span>{{ queryParamsSubAdd.parentTask }}</span>
          </td>
          <td v-if="titleSub == '新建子任务'"><span class="label">所属父任务：</span><span>{{ parentTaskCode }}</span></td>
        </tr>
        <tr v-if="titleSub == '新建子任务'">
          <td colspan="2">
            <el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" label-width="140px">
              <el-form-item label="子任务名称：" prop="taskName">
                <el-input placeholder="请输入子任务名称" clearable v-model="queryParamsSubAdd.taskName" />
              </el-form-item>
            </el-form>
          </td>
        </tr>
        <tr v-if="titleSub == '新建子任务'">
          <td>
            <el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" label-width="140px">
              <el-form-item label="所在省：" prop="subdistrictList">
                <el-select placeholder="请选择省" v-model="queryParamsSubAdd.subdistrictList" clearable>
                  <el-option
                    v-for="item in districtListName.filter(item => !subTaskData.some(cur => cur.taskDistrict.includes(item.value)))"
                    :key="item.id" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-form>
          </td>
          <td>
            <el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" label-width="140px">
              <el-form-item v-if="queryParamsSubAdd.groupName != ''">
                <span class="label">承担小组:</span><span>{{ queryParamsSubAdd.groupName }}</span>
              </el-form-item>
            </el-form>
          </td>
        </tr>
        <tr v-if="titleSub == '修改子任务'">
          <td colspan="2">
            <el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" :inline="true" label-width="140px">
              <el-form-item label="子任务名称：" prop="taskName">
                <el-input placeholder="请输入子任务名称" clearable v-model="queryParamsSubAdd.taskName" />
              </el-form-item>
            </el-form>
          </td>
        </tr>
        <tr v-if="titleSub == '修改子任务'">
          <td colspan="2">
            <span class="label">任务区域：</span><span>{{ queryParamsSubAdd.taskDistrict }}</span>
          </td>
          <!--<td>
            <span class="label">所属父任务：</span><span>{{ queryParamsSubAdd.parentTask }}</span>
          </td>-->
        </tr>
        <tr v-if="queryParamsSubAdd.groupName != '' && titleSub == '修改子任务'">
          <td><span class="label">承担小组：</span><span>{{ queryParamsSubAdd.groupName }}</span>
            <el-button plain style="margin-left:20px" @click="fenPeiAdd()">修改分配</el-button></td>
        </tr>
      </table>
      <div v-if="titleSub == '新建子任务'">
        <h3><span></span> 分配小组</h3>
        <fpGrop @queryGroup="queryGroup" ref="fpRef" />
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="okSubAdd">保 存</el-button>
          <template v-if="titleSub == '新建子任务'">
            <el-button type="primary" @click="okSubAddNext">保存并创建下一个</el-button>
          </template>
          <el-button plain @click="cancelAddSub">取 消</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 分配的弹出框 -->
    <el-dialog v-model="openFp" title="分配小组" width="900px" append-to-body v-if="openFp">
      <p class="dialogTitle">分配小组</p>
      <fpGrop @queryGroup="queryGroup" ref="fpRef" />
      <!-- <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="okFp()" :disabled="queryGroupObj == undefined">确定</el-button>
          <el-button @click="cancelP">取消</el-button>
        </div>
      </template> -->
    </el-dialog>
    <!-- 查看弹出框 -->
    <el-dialog v-model="openDetail" title="查看任务" width="900px">
      <detailAssess :detilList="detilList" />
    </el-dialog>
    <!-- 行政区域选择 -->
    <div class="areaDialog" v-show="openArea">
      <div class="close">
        <el-icon>
          <Close @click="closeSelect" />
        </el-icon>
      </div>
      <el-form :model="form" :rules="rules" ref="rulesForm" label-width="100px">
        <el-form-item label="选择地区" prop="taskDistrict" style="width: 280px;">
          <el-cascader v-model="form.taskDistrict" placeholder="请选择地区" :props="props" clearable separator=","
            collapse-tags collapse-tags-tooltip @change="getCheckedArea" ref="checkedAreaRef" :options="optionsSelect">
          </el-cascader>
        </el-form-item>
      </el-form>
      <el-button @click="add()" type="primary" style="margin: 20px 0">新建任务</el-button>
    </div>
    <!-- 关联抽样调查点 -->
    <el-dialog v-model="relationDialog" title="关联抽样调查点" width="1050px" append-to-body @close="closeRelation" destroy-on-close>
      <p></p>
      <el-form :inline="true" ref="relationFormRef" :model="relationForm" label-width="85px">
        <el-form-item label="省" prop="province">
          <el-select v-model="relationForm.province" placeholder="请选择" @change="chooseRelationProvince" clearable>
            <el-option v-for="(value, key) in relationProvince" :key="key" :label="key" :value="value" />
          </el-select>
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-select v-model="relationForm.city" placeholder="请选择" @change="chooseRelationCity" clearable>
            <el-option v-for="item in relationCity" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="区/县" prop="county">
          <el-select v-model="relationForm.county" placeholder="请选择" clearable>
            <el-option v-for="item in relationCounty" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属乡镇" prop="township">
          <el-input v-model="relationForm.township" placeholder="请输入所属乡镇" clearable />
        </el-form-item>
        <el-form-item label="调研点名称" prop="SurveyPointName">
          <el-input v-model="relationForm.SurveyPointName" placeholder="请输入调研点名称" clearable />
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" @click="getRelationTable">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="relationData" ref="relationTable" v-loading="relationLoading" stripe :row-key="getRowKeys"
        @selection-change="relationSelectionChange">
        <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
        <el-table-column label="调研点名称" align="center" prop="fieldSurveyName" />
        <el-table-column label="省" align="center" prop="province" />
        <el-table-column label="市" align="center" prop="city" />
        <el-table-column label="区/县" align="center" prop="area" />
        <el-table-column label="所属乡镇" align="center" prop="township" />
        <el-table-column label="操作" align="center">
          <template #default="{ row }">
            <el-button type="text" @click="viewRelation(row.id)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="relationTotal > 0" :total="relationTotal" v-model:page="relationForm.page"
        v-model:limit="relationForm.rows" @pagination="getRelationTable" />
      <template #footer>
        <el-button type="primary" @click="saveRelation" style="text-align: right;">确定</el-button>
      </template>
    </el-dialog>
    <!-- 关联抽样调查点查看 -->
    <ViewSamplingSurveyVue v-model:open="viewRelationOpen" :id="samplingSurveyId"></ViewSamplingSurveyVue>
  </div>
</template>
<script setup name="assess">
//地图
import AssessMap from '@/map/taskmanage/assess/map.vue';
//地图空间分析
import { getSubTaskRegionIntersection } from "@/map/taskmanage/sceneexamine/mapUtil.js";
import fpGrop from "@/components/FpGroup/index.vue";
import detailAssess from "./detailAssess.vue";
import { getProvince, getChildArea } from "@/api/system/division";
import { getProvinces, getYear, getDistrict } from "@/utils/group.js";
import { queryProvinceCityCountyNameCodeListByGeomText } from "@/api/taskmanage/taskRegionQuery";
import ViewSamplingSurveyVue from './viewSamplingSurvey.vue';
import {
  getTask,
  delTask,
  updateTask,
  addSubTask,
  addTask,
  detailTask,
  groupFp,
  getTaskBian,
  getSubTaskBian,
  getSubTask,
  getAllTaskList,
  getCityIdTaskDistrict,
  getSamplingSurveyPoint,
  saveSurveySamplingPoint
} from "@/api/taskmanage/assess";
import { getAreaTree, getDistrictBoundary } from "@/api/taskmanage/sceneExame"
import { uploadShpFile, uploadTxtFile } from "@/api/taskmanage/taskRegionQuery";
import { ElMessageBox } from "element-plus";
const { proxy } = getCurrentInstance();
const taskDistrictName = ref("");
const checkedAreaRef = ref();
const props = { multiple: true };
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const options = [
  {
    value: "0",
    label: "未分配",
  },
  {
    value: "1",
    label: "进行中",
  },
  {
    value: "2",
    label: "审核中",
  },
  {
    value: "3",
    label: "已结束",
  },
];
const newYear = getYear();
const optionsYear = [
  {
    value: String(newYear),
    label: String(newYear),
    id: 1,
  },
  {
    value: String(newYear + 1),
    label: String(newYear + 1),
    id: 2,
  },
  {
    value: String(newYear + 2),
    label: String(newYear + 2),
    id: 3,
  },
];
const loading = ref(true);
const loading1 = ref(true);
const provinceData = ref([]); //省
const cityData = ref([]); //市
const areaData = ref([]); //区、县
const openFp = ref(false);
const fpId = ref({
  id: undefined,
  parentId: undefined,
  taskName: undefined,
  createUser: undefined
});
const openAdd = ref(false);
const openAddSub = ref(false);
const openArea = ref(false);
const title = ref("");
const titleSub = ref("");
const activeName = ref("first");
const queryGroupObj = ref(undefined);
const openDetail = ref(false);
const total = ref(0);
const num = ref();
const parentTaskCode = ref();
const parentTaskYear = ref();
const parentTaskId = ref();
const numAdd = ref(2);
const districtListName = ref("");
const delFlag = ref(false);
const rules = reactive({
  taskDistrict: [{ required: true, message: "请选择地区", trigger: "change" }],
  taskYear: [{ required: true, message: "请选择年份", trigger: "change" }],
  taskName: [{ required: true, message: "请输入任务名称", trigger: "blur" }],
});
const rules2 = reactive({
  taskName: [{ required: true, message: "请输入任务名称", trigger: "blur" }],
  subdistrictList: [
    { required: true, message: "请输入选择省份", trigger: "blur" },
  ],
});
let detilList = reactive({
  preAssessTaskEntity: {
    taskYear: undefined,
    taskNum: undefined,
    taskName: undefined,
    taskArea: undefined,
    taskRegion: undefined,
    districtList: undefined,
    groupName: undefined,
    groupLeader: undefined,
    taskDistrict: undefined,
  },
  expertlist: undefined,
  memberlist: "",
});
const data = reactive({
  form: {
    taskDistrict: "",
  },
  selectProvince: [],
  listData: [],
  queryParams: {
    page: 1,
    rows: 10,
    taskNum: "",
    taskName: "",
    taskStatus: "",
    province: "",
    city: "",
    county: "",
  },
  queryParamsAdd: {
    taskYear: "",
    taskNum: "",
    taskName: "",
    taskArea: "",
    taskRegion: "",
    parentdistrictList: [],
    taskDistrict: "",
    groupName: "",
    groupLeader: "",
    groupId: "",
    groupLeaderId: "",
    regionCodes: ""//地图行政区划code,code字符串
  },
  queryParamsSubAdd: {
    taskYear: "",
    taskNum: "",
    taskName: "",
    taskArea: "",
    taskRegion: "",
    subdistrictList: "",
    taskDistrict: "",
    groupName: "",
    groupLeader: "",
    groupLeaderId: "",
    groupId: "",
    regionCodes: ""//地图行政区划code,code字符串
  },
  subTaskData: [],
  subDataPage: {
    page: 1,
    rows: 10,
  },
  optionsSelect: [],
  selectArea: [],
});

let {
  form,
  queryParams,
  listData,
  queryParamsAdd,
  queryParamsSubAdd,
  selectArea,
  subTaskData,
  optionsSelect,
} = toRefs(data);

//地图传参--start
const completeRefreshAssess = ref(false);//防止刷新后地图不显示
const allListData = ref([]);
const isSaveMapPolygon = ref(false);//判断是否完成保存任务区域
const xzqhSelect = () => {//行政区划选择区域
  areaSelect();
}

//导入工作区域shp/txt
const showHideUploadDivBool = ref(false);//是否显示上传面板
const uploadType = ref("0");//上传类型0shp 1txt
const textarea = ref("");//上传文件只读显示文本框
const minList = ref([]);//要上传的文件的后缀名数组
const nameList = ref([]);//要上传的文件的文件名数组
const importShpTxtWkt = ref("");//导入任务区域空间数据wkt
const showHideUploadDiv = (bool) => {
  importShpTxtWkt.value = "";
  textarea.value = "";
  showHideUploadDivBool.value = bool;
}
const changeUploadType = () => {//切换上传类型
  textarea.value = "";
}
const uploadFileChange = () => {//选择文件shp
  let uploadinputFiles = [];
  if (uploadType.value == "1") {//txt文件
    uploadinputFiles = document.getElementById("sceneexamine-button-selectfile-txt").files;
  } else {//shp文件
    uploadinputFiles = document.getElementById("sceneexamine-button-selectfile-shp").files;
  }
  console.log(uploadinputFiles);
  minList.value = [];
  nameList.value = [];
  let text = "";
  for (let i = 0; i < uploadinputFiles.length; i++) {
    console.log("uploading: " + uploadinputFiles[i].name);
    text += uploadinputFiles[i].name + "\n";
    // 获取这个文件的后缀名
    minList.value.push(uploadinputFiles[i].name.slice(uploadinputFiles[i].name.length - 3, uploadinputFiles[i].name.length));
    nameList.value.push(uploadinputFiles[i].name.split(".")[0]);
  }
  textarea.value = text;
}
const uploadFileClick = () => {//上传
  let uploadinput = null;
  if (textarea.value == "") {
    proxy.$modal.msgWarning("上传前请先选择文件!");
    return;
  }
  if (uploadType.value == "1") {//txt文件
    if (minList.value.length != 1) {
      proxy.$modal.msgWarning('上传数量限制:.txt文件1个');
      return;
    }
    uploadinput = document.getElementById("sceneexamine-button-selectfile-txt");
  } else {//shp文件
    if (!judgeIsOnce(minList.value)) {
      proxy.$modal.msgWarning('上传数量限制:.prj、.shp文件各1个');
      return;
    } else if (!judgeName(nameList.value)) {
      proxy.$modal.msgWarning("文件名请保持一致！");
      return;
    }
    uploadinput = document.getElementById("sceneexamine-button-selectfile-shp");
  }
  if (uploadinput != null && uploadinput.files.length == 0) {
    proxy.$modal.msgWarning("上传前请先选择文件!");
    return;
  }

  let formData = new FormData();
  for (let i = 0; i < uploadinput.files.length; i++) {
    formData.append('files', uploadinput.files[i]);
  }
  formData.append('uploadType', uploadType.value);
  mapLoading("正在上传...");
  if (uploadType.value == "1") {//txt文件
    uploadTxtFile(formData).then((response) => {
      nextTick(() => {
        let msg = response.data;
        mapLoading(null);
        let messageType = "error";
        if (msg.indexOf("导入成功.") != -1) {
          messageType = "success";
          importShpTxtWkt.value = msg.split("导入成功.")[1];
          msg = "导入成功";
        }
        ElMessageBox.alert(msg, '系统信息', {
          confirmButtonText: '确认',
          type: messageType,
          dangerouslyUseHTMLString: true,
        });
      });
    }).catch(err => {
      mapLoading(null);
    });
  } else {//shp文件
    uploadShpFile(formData).then((response) => {
      nextTick(() => {
        let msg = response.data;
        mapLoading(null);
        let messageType = "error";
        if (msg.indexOf("导入成功.") != -1) {
          messageType = "success";
          importShpTxtWkt.value = msg.split("导入成功.")[1];
          msg = "导入成功";
        }
        ElMessageBox.alert(msg, '系统信息', {
          confirmButtonText: '确认',
          type: messageType,
          dangerouslyUseHTMLString: true,
        });
      });
    }).catch(err => {
      mapLoading(null);
    });
  }
}
function importTemplate(name) {// 模板下载
  proxy.download("/taskRegionQuery/downloadTxt", {
    fileName: name
  }, name);
}
//校验shp文件类型
function judgeIsOnce(list) {
  // ["prj","shp"];
  let prj = 0, shp = 0;
  for (let i = 0; i < list.length; i++) {
    let item = list[i];
    if (item == 'prj') prj++;
    if (item == 'shp') shp++;
  }
  if (prj == 1 && shp == 1) return true;
  else return false;
}
//校验shp文件名称
function judgeName(list) {
  let name = list[0];
  let result = list.filter(function (item) {
    return item == name;
  })
  if (result.length == list.length) return true;
  else return false;
}

const mapNewTask = (temp) => {//新建任务
  isSaveMapPolygon.value = false;//判断是否完成保存任务区域
  getTaskNum();
  subTaskData.value = [];
  title.value = "新建任务";
  num.value = 0;
  openAdd.value = true;
  resetAdd();
  console.log('#####', temp)
  queryParamsAdd.value.taskArea = temp.taskArea;
  queryParamsAdd.value.taskRegion = temp.taskRegion;
  queryParamsAdd.value.parentdistrictList = temp.parentdistrictList;
  queryParamsAdd.value.regionCodes = "";//地图行政区划code,code字符串
  console.log(temp.parentdistrictList);
  taskDistrictName.value = temp.parentdistrictList.join(',');
  districtListName.value = getMapProvinces(taskDistrictName.value);
}
const mapUpdTask = (row) => {//修改任务
  updateParentHandle(row);
}
const mapDelTask = (row) => {//删除任务
  delSubTask(row);
}
const mapLoading = (msg) => {//地图查询loading
  if (msg != null) {
    proxy.$modal.loading(msg);
  } else {
    proxy.$modal.closeLoading();
  }
}
const mapShowTask = (id) => {//查看任务
  handleDetil(id);
}
//处理地图圈选省份
function getMapProvinces(taskDistrict) {
  const str = taskDistrict.replace(/-/g, ",")
  const arr = [...new Set(str.split(","))]
  let newArr = []
  arr.forEach(item => {
    if (item.indexOf('省') != -1) {
      newArr.push(item)
    } else if (item == '北京市' || item == '天津市' || item == '上海市' || item == '重庆市' || item == '内蒙古自治区' || item == '内蒙古自治区' || item == '广西壮族自治区' || item == '西藏自治区' || item == '宁夏回族自治区' || item == '新疆维吾尔自治区' || item == '香港特别行政区' || item == '澳门特别行政区') {
      newArr.push(item)
    }
  })
  let brr = []
  brr = newArr.map(
    (item, index) => {
      return Object.assign({}, { value: item, label: item, id: index + 1 });
    }
  );
  return brr
}
//获取行政区划总面积
function getAllSelectArea(array) {
  let areaCount = 0;
  if (array != null && array.length > 0) {
    for (let i = 0; i < array.length; i++) {
      let name = array[i];
      let arr = name.split('-');
      console.log(name + "," + arr.length);
      if (arr.length == 1) {//省
        let province = arr[0];
        let areaTemp = getAreaByAllName("1", province, null, null);//根据行政区划全称获取省市区面积信息
        console.log("areaTemp" + areaTemp);
        areaCount += areaTemp;
        console.log("areaCount" + areaCount);
      } else if (arr.length == 2) {//市或直辖市的区县
        let province = arr[0];
        let city = arr[1];
        let areaTemp = getAreaByAllName("2", province, city, null);//根据行政区划全称获取省市区面积信息
        console.log("areaTemp" + areaTemp);
        areaCount += areaTemp;
        console.log("areaCount" + areaCount);
      } else if (arr.length == 3) {//区县
        let province = arr[0];
        let city = arr[1];
        let area = arr[2];
        let areaTemp = getAreaByAllName("3", province, city, area);//根据行政区划全称获取省市区面积信息
        console.log("areaTemp" + areaTemp);
        areaCount += areaTemp;
        console.log("areaCount" + areaCount);
      }
    }
  }
  if (areaCount > 0) {
    areaCount = areaCount.toFixed(3);//四舍五入保留3位小数
  }

  return areaCount;
}
function getAreaByAllName(type, province, city, area) {//根据行政区划全称获取省市区面积信息
  //type:0省 | 1市 | 2区县
  let areaCount = 0;
  let districtTreeDataList = districtTreeList.value;
  if (districtTreeDataList != null && districtTreeDataList != "") {
    //获取行政区划树列表
    let treeList = districtTreeDataList;
    if (treeList != null && treeList.length > 0) {
      for (let i = 0; i < treeList.length; i++) {
        let provinceData = treeList[i];//省节点
        if (provinceData != null) {
          let provinceName = provinceData.name;//省
          if (type == "1" && province == provinceName) {
            let cityList = provinceData.children;//市列表
            if (cityList != null) {
              for (let j = 0; j < cityList.length; j++) {
                let cityData = cityList[j];
                if (cityData != null) {
                  let areaList = cityData.children;//区县列表
                  if (areaList != null && areaList.length > 0) {
                    for (let j = 0; j < areaList.length; j++) {
                      let areaData = areaList[j];
                      if (areaData != null) {
                        areaCount += areaData.area / 1000000;//平方公里
                      }
                    }
                  } else {//直辖市
                    areaCount += cityData.area / 1000000;//平方公里
                  }
                }
              }
            }
            return areaCount;
          }
          let cityList = provinceData.children;//市列表
          if (cityList != null) {
            for (let j = 0; j < cityList.length; j++) {
              let cityData = cityList[j];
              if (cityData != null) {
                let cityName = cityData.name;//市
                if (type == "2" && city == cityName) {
                  let areaList = cityData.children;//区县列表
                  if (areaList.length > 0) {
                    for (let j = 0; j < areaList.length; j++) {
                      let areaData = areaList[j];
                      if (areaData != null) {
                        areaCount += areaData.area / 1000000;//平方公里
                      }
                    }
                  } else {//直辖市的区县
                    areaCount = cityData.area / 1000000;//平方公里
                  }
                  return areaCount;
                }
                let areaList = cityData.children;//区县列表
                if (areaList != null) {
                  for (let j = 0; j < areaList.length; j++) {
                    let areaData = areaList[j];
                    if (areaData != null) {
                      let areaName = areaData.name;//区县
                      if (type == "3" && area == areaName) {
                        areaCount += areaData.area / 1000000;//平方公里
                        return areaCount;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  return areaCount;
}
//查询行政区划树列表
const districtTreeList = ref([]);
const districtBoundaryList = ref([]);//行政区划经纬度信息
const districtCount = ref(0);//选择的行政区划数量
//查询行政区划经纬度信息
function getDistrictBoundaryByCode(codeList) {
  for (let m = 0; m < codeList.length; m++) {
    let code = codeList[m];
    //查询行政区划经纬度信息
    console.log("查询行政区划经纬度信息" + code);
    getDistrictBoundary(code).then((response) => {
      nextTick(() => {
        //districtBoundaryList.value.push(response.data.coordinate);
        //截取数据防止报错--仅用于展示不保存
        let subStr = response.data.coordinate;
        subStr = subStr.substring(0, 1000);
        districtBoundaryList.value.push(subStr);
        if (districtCount.value == districtBoundaryList.value.length) {//判断是否全部查询完毕
          let region = "";
          let list = districtBoundaryList.value;
          for (let i = 0; i < list.length; i++) {
            if (i > 0) {
              region += ";";
            }
            region += list[i];
          }
          queryParamsAdd.value.taskRegion = region;
          //新建任务
          proxy.$refs["rulesForm"].validate((vaild) => {
            if (!vaild) {
              return;
            }
            getTaskNum();
            subTaskData.value = [];
            title.value = "新建任务";
            num.value = 0;
            openAdd.value = true;
            //地图获取行政区划总面积
            let area = getAllSelectArea(queryParamsAdd.value.parentdistrictList);
            queryParamsAdd.value.taskArea = area.toString();
            proxy.$modal.closeLoading();
          });
        }
      });
    });
  }
}
//根据所有省市县全名字符串获取codelist
function getCodeByAllName(allName) {
  let allCodeList = [];
  if (allName != null && allName != "") {
    let array = allName.split("、");
    //获取行政区划树列表
    let treeList = districtTreeList.value;
    for (let i = 0; i < array.length; i++) {
      let name = array[i];
      let code = null;
      let arr = name.split('-');
      if (arr.length == 1) {//省或直辖市
        if (treeList != null && treeList.length > 0) {
          for (let i = 0; i < treeList.length; i++) {
            let provinceData = treeList[i];//省节点
            if (provinceData != null) {
              let provinceName = provinceData.name;//省
              if (name == provinceName) {
                let provinceCode = provinceData.code;//省编码
                code = provinceCode;
                break;
              }
            }
          }
        }
      } else if (arr.length == 2) {//市或直辖市的区县
        if (treeList != null && treeList.length > 0) {
          for (let i = 0; i < treeList.length; i++) {
            let provinceData = treeList[i];//省节点
            if (provinceData != null) {
              let provinceName = provinceData.name;//省
              if (arr[0] == provinceName) {
                let bool = false;
                let cityList = provinceData.children;//市列表
                if (cityList != null) {
                  for (let j = 0; j < cityList.length; j++) {
                    let cityData = cityList[j];
                    if (cityData != null) {
                      let cityName = cityData.name;//市
                      if (arr[1] == cityName) {
                        let cityCode = cityData.code;//市编码
                        code = cityCode;
                        bool = true;
                        break;
                      }
                    }
                  }
                }
                if (bool) {
                  break;
                }
              }
            }
          }
        }
      } else if (arr.length == 3) {//区县
        if (treeList != null && treeList.length > 0) {
          for (let i = 0; i < treeList.length; i++) {
            let provinceData = treeList[i];//省节点
            let bool = false;
            if (provinceData != null) {
              let provinceName = provinceData.name;//省
              if (arr[0] == provinceName) {
                let cityList = provinceData.children;//市列表
                if (cityList != null) {
                  for (let j = 0; j < cityList.length; j++) {
                    let cityData = cityList[j];
                    if (cityData != null) {
                      let cityName = cityData.name;//市
                      if (arr[1] == cityName) {
                        let areaList = cityData.children;//区县列表
                        if (areaList != null) {
                          for (let j = 0; j < areaList.length; j++) {
                            let areaData = areaList[j];
                            if (areaData != null) {
                              let areaName = areaData.name;//区县
                              if (arr[2] == areaName) {
                                let areaCode = areaData.code;//区县编码
                                code = areaCode;
                                bool = true;
                                break;
                              }
                            }
                          }
                        }
                        if (bool) {
                          break;
                        }
                      }
                    }
                  }
                }
              }
            }
            if (bool) {
              break;
            }
          }
        }
      }
      //添加code
      allCodeList.push(code);
    }
  }

  return allCodeList;
}
function getProvinceCodeByAllName(allName) {
  let allCodeList = [];
  if (allName != null && allName != "") {
    let array = allName.split("、");
    //获取行政区划树列表
    let treeList = districtTreeList.value;
    for (let i = 0; i < array.length; i++) {
      let name = array[i].split('-')[0];
      let code = null;
      let arr = name;
      if (treeList != null && treeList.length > 0) {
        for (let i = 0; i < treeList.length; i++) {
          let provinceData = treeList[i];//省节点
          if (provinceData != null) {
            let provinceName = provinceData.name;//省
            if (name == provinceName) {
              let provinceCode = provinceData.code;//省编码
              code = provinceCode;
              break;
            }
          }
        }
      }
      allCodeList.push(code);
    }
  }
  console.log([...new Set(allCodeList)]);
  return [...new Set(allCodeList)];
}

//获取新建子任务地图区域信息
function getSubTaskMapRegion(type) {
  //type:okSubAdd保存子任务|okSubAddNext保存并创建下一个子任务
  proxy.$modal.loading("正在保存，请稍候...");
  //地图获取行政区划总面积
  let area = getAllSelectArea([queryParamsSubAdd.value.subdistrictList]);
  queryParamsSubAdd.value.taskArea = area.toString();
  let provinceName = queryParamsSubAdd.value.subdistrictList;//省名
  //根据所有省市县全名字符串获取codelist
  let codeList = getCodeByAllName(provinceName);
  console.log("查询行政区划codeList" + codeList);
  //选择的行政区划数量
  districtCount.value = codeList.length;
  console.log("选择的行政区划数量" + districtCount.value);
  let regionCodes = "";
  for (let i = 0; i < codeList.length; i++) {
    let code = codeList[i];
    if (i > 0) {
      regionCodes += ",";
    }
    regionCodes += code;
  }
  districtBoundaryList.value = [];//清空行政区划经纬度
  if (queryParamsAdd.value.taskRegion.indexOf("MULTIPOLYGON") == -1) {//地图圈选父任务
    console.log("地图圈选父任务");
    queryParamsSubAdd.value.taskRegion = queryParamsAdd.value.taskRegion;
    queryParamsSubAdd.value.regionCodes = "";//清空
  } else {//行政区划选择父任务
    console.log("行政区划选择父任务");
    let parentRegionCodes = queryParamsAdd.value.regionCodes;
    console.log("父任务行政区划code" + parentRegionCodes + ",子任务选择省份" + regionCodes);
    let tempCode = regionCodes.substring(0, 2);//省份code保留2位
    console.log("tempCode:" + tempCode);
    let parentRegionCodeArray = parentRegionCodes.split(",");
    let childRegionCode = "";
    for (let i = 0; i < parentRegionCodeArray.length; i++) {
      let parentRegionCode = parentRegionCodeArray[i];
      if (parentRegionCode.indexOf(tempCode) == 0) {//省份相同2位
        if (childRegionCode != "") {
          childRegionCode += ",";
        }
        childRegionCode += parentRegionCode;
      }
    }
    console.log("子任务行政区划" + childRegionCode);
    queryParamsSubAdd.value.regionCodes = childRegionCode;//地图行政区划code,code字符串
    console.log("行政区划选择父任务");
  }
  console.log(queryParamsAdd.value);
  //查询子任务行政区划经纬度信息
  for (let m = 0; m < codeList.length; m++) {
    let code = codeList[m];
    //查询行政区划经纬度信息
    console.log("查询子任务行政区划经纬度信息" + code);
    getDistrictBoundary(code).then((response1) => {
      nextTick(() => {
        console.log("查询子任务行政区划经纬度信息result:");
        console.log(response1.data);
        districtBoundaryList.value.push(response1.data.coordinate);
        if (districtCount.value == districtBoundaryList.value.length) {//判断是否全部查询完毕
          let region = "";
          let list = districtBoundaryList.value;
          for (let i = 0; i < list.length; i++) {
            if (i > 0) {
              region += ";";
            }
            region += list[i];
          }
          console.log("全部查询完毕--子任务行政区划经纬度信息");
          if (queryParamsAdd.value.taskRegion.indexOf("MULTIPOLYGON") == -1) {//地图圈选父任务
            console.log("获取子任务区域经纬度（地图圈选父任务与省份的交集）");
            //获取子任务区域经纬度（地图圈选父任务与省份的交集）
            queryParamsSubAdd.value.taskRegion = getSubTaskRegionIntersection(queryParamsAdd.value.taskRegion, region);
          } else {//行政区划选择父任务
            //截取数据防止报错--仅用于展示不保存
            region = region.substring(0, 10000);
            queryParamsSubAdd.value.taskRegion = region;
          }
          console.log(queryParamsSubAdd.value.subdistrictList);
          //queryParamsSubAdd.value.taskDistrict = queryParamsSubAdd.value.subdistrictList;//任务区域-省份
          console.log("子任务地图行政区划code,code字符串：");
          console.log(queryParamsSubAdd.value.regionCodes);
          proxy.$modal.closeLoading();
          if (type == "okSubAdd") {//
            proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
              if (!vaild) {
                return;
              }
              if (queryGroupObj.value) {
                queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
                queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
                queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
                queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
              }
              console.log("输出任务地区：");
              console.log(queryParamsSubAdd.value.subdistrictList);
              // 新增
              proxy.$modal.loading();
              if (titleSub.value == "新建子任务") {
                if (numAdd.value == 1) {
                  addSubTask({
                    ...queryParamsSubAdd.value,
                    subdistrictList: [queryParamsSubAdd.value.subdistrictList],
                    taskYear: parentTaskYear.value,
                    parentTask: parentTaskCode.value,
                    parentId: parentTaskId.value,
                    parentdistrictList: queryParamsAdd.value.parentdistrictList,
                  }).then((response) => {
                    proxy.$modal.closeLoading();
                    openAddSub.value = false;
                    proxy.$modal.msgSuccess(response.data.message);
                    resetSubData();
                    getList();
                    queryGroupObj.value = undefined;
                    getSubList(parentTaskId.value);
                  }).catch(err => { proxy.$modal.closeLoading(); });
                } else {
                  addTask({
                    parentTask: queryParamsAdd.value,
                    subTask: {
                      ...queryParamsSubAdd.value,
                      subdistrictList: [queryParamsSubAdd.value.subdistrictList],
                      taskYear: parentTaskYear.value,
                      parentTask: parentTaskCode.value,
                    },
                  }).then((response) => {
                    proxy.$modal.closeLoading();
                    numAdd.value = 1;
                    openAddSub.value = false;
                    proxy.$modal.msgSuccess("保存成功");
                    resetSubData();
                    getSubList(response.data.parentTaskId);
                    queryGroupObj.value = undefined;
                    parentTaskId.value = response.data.parentTaskId;
                    //地图传参
                    isSaveMapPolygon.value = true;
                  }).catch(err => { proxy.$modal.closeLoading(); });
                }
              }
            });
          } else if (type == "okSubAddNext") {//保存并创建下一个子任务
            proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
              if (!vaild) {
                return;
              }
              // 新增
              proxy.$modal.loading();
              if (queryGroupObj.value) {
                queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
                queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
                queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
                queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
              }
              if (numAdd.value == 1) {
                addSubTask({
                  ...queryParamsSubAdd.value,
                  subdistrictList: [queryParamsSubAdd.value.subdistrictList],
                  taskYear: parentTaskYear.value,
                  parentTask: parentTaskCode.value,
                  parentId: parentTaskId.value,
                  parentdistrictList: queryParamsAdd.value.parentdistrictList,
                }).then((response) => {
                  proxy.$modal.closeLoading();
                  proxy.$modal.msgSuccess("保存成功");
                  getSubTaskNum(parentTaskCode.value);
                  resetSubData();
                  getList();
                  queryGroupObj.value = undefined;
                  getSubList(parentTaskId.value);
                }).catch(err => { proxy.$modal.closeLoading(); });
              } else {
                addTask({
                  parentTask: queryParamsAdd.value,
                  subTask: {
                    ...queryParamsSubAdd.value,
                    subdistrictList: [queryParamsSubAdd.value.subdistrictList],
                    taskYear: parentTaskYear.value,
                    parentTask: parentTaskCode.value,
                  },
                }).then((response) => {
                  proxy.$modal.closeLoading();
                  proxy.$modal.msgSuccess("保存成功");
                  numAdd.value = 1;
                  getSubTaskNum(parentTaskCode.value);
                  resetSubData();
                  // rulesFormSubAdd.value.clearValidate();
                  getSubList(response.data.parentTaskId);
                  queryGroupObj.value = undefined;
                  parentTaskId.value = response.data.parentTaskId;
                  //地图传参
                  isSaveMapPolygon.value = true;
                }).catch(err => { proxy.$modal.closeLoading(); });
              }
            });
          }
        }
      });
    });
  }
}

//地图圈选查询行政区划结果列表
const taskRegionResultNameCodeList = ref([]);
//根据地图圈选区域，查询行政区划--省|市|区县的名称和code列表
function queryTaskRegionNameCodeListByGeomText(geomText) {
  console.log("查询行政区划名称和code列表" + geomText);
  queryProvinceCityCountyNameCodeListByGeomText(geomText).then((response) => {
    nextTick(() => {
      console.log("查询行政区划名称和code列表result:");
      console.log(response.data);
      taskRegionResultNameCodeList.value = response.data;
    });
  });
}
//地图传参--end


/*切换标签页*/
function handleClick(tab, event) {
  activeName.value = tab.paneName;
  if (tab.index == 1) {
    openArea.value = false;
    resetArea();
    getList();
  } else {
    //隐藏地图
    completeRefreshAssess.value = false;
    //地图查询全部任务
    getAllList();
  }
}

const handleSelectionChange = (selection) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
  selection.forEach((item) => {
    if (item.taskStatus == "3" || item.taskStatus == "2") {
      delFlag.value = false;
    } else {
      delFlag.value = true;
    }
  });
};

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  cityData.value = [];
  areaData.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 获取省列表 */
function getProvinceData() {
  getProvince().then((response) => {
    provinceData.value = response.data;
  });
}

function chooseProvince(value) {
  queryParams.value.city = null;
  queryParams.value.county = null;
  queryParams.value.province = value.name;
  cityData.value = [];
  areaData.value = [];
  getChildArea(value.id).then((response) => {
    cityData.value = response.data;
  });
  /*provinceData.value.map((item) => {
    //遍历数据
    if (item.id == value.id) {
      if (
        item.name == "北京市" ||
        item.name == "天津市" ||
        item.name == "上海市" ||
        item.name == "重庆市"
      ) {
        cityData.value.push(JSON.parse(JSON.stringify(item)));
      } else {
        getChildArea(value.id).then((response) => {
          cityData.value = response.data;
        });
      }
      return;
    }
  });*/
}

function chooseCity(value) {
  queryParams.value.city = value.name;
  queryParams.value.county = null;
  areaData.value = [];
  getChildArea(value.id).then((response) => {
    areaData.value = response.data;
  });
}

function chooseCounty(value) {
  queryParams.value.county = value.name;
}

// 部门  树形数据
// 处理数据
function disposeata(data) {
  data.forEach((item) => {
    item.label = item.name;
    item.key = item.id;
    item.children && disposeata(item.children);
  });
  return data;
}
function getTreeselect() {
  getAreaTree().then((response) => {
    nextTick(() => {
      optionsSelect.value = disposeata(JSON.parse(response.data));
      console.log("行政区划列表");
      //地图行政区划列表
      districtTreeList.value = optionsSelect.value;
      console.log(districtTreeList.value);
    });
  });
}

function getCheckedArea() {
  let taskDistrict = checkedAreaRef.value.getCheckedNodes();
  taskDistrict = taskDistrict.filter(option => !(option.parent && option.parent.checked))
  queryParamsAdd.value.parentdistrictList = taskDistrict.map((item, index) => {
    return item.pathLabels.join("-");
  });
  var arr = JSON.parse(JSON.stringify(queryParamsAdd.value.parentdistrictList));
  queryParamsAdd.value.parentdistrictList = arr;
  taskDistrictName.value = getDistrict(arr);
  districtListName.value = getProvinces(taskDistrictName.value);
}

/** 获取列表操作 */
function getList() {
  if (activeName.value == "first") {
    //地图查询全部任务
    getAllList();
  } else {
    loading.value = true;
    getTask(queryParams.value).then((response) => {
      console.log(response)
      listData.value = response.data.rows;
      loading.value = false;
      total.value = response.data.total;
    });
  }
}

//地图查询全部任务
function getAllList() {
  // loading.value = true;
  completeRefreshAssess.value = true;//防止地图刷新后不显示--
  //地图查询全部任务
  getAllTaskList().then((response) => {
    nextTick(() => {
      console.log("地图查询全部任务：");
      console.log(response.data);
      allListData.value = response.data;
      //completeRefreshAssess.value = true;//防止地图刷新后不显示--
      // loading.value = false;
    });
  });
}

/** 获取子列表操作 */
function getSubList(parentId) {
  loading1.value = true;
  getSubTask({ parentTaskId: parentId }).then((response) => {
    nextTick(() => {
      subTaskData.value = response.data;
      if (districtListName.value.filter(item => !subTaskData.value.some(cur => cur.taskDistrict.includes(item.value))).length == 0) {
        openAddSub.value = false;
      }
    });
    loading1.value = false;
  });
}

/** 删除按钮操作 */
function handleDelete() {
  if (delFlag.value) {
    proxy.$modal
      .confirm("是否确认删除该任务关联的所有信息，请确认是否要删除？")
      .then(function () {
        return delTask(ids.value.join(","));
      })
      .then(() => {
        proxy.$refs['tableRef']?.clearSelection();
        getList();
        proxy.$modal.msgSuccess("删除成功");
      })
      .catch(() => { });
  } else {
    proxy.$modal.msgWarning("审核、结束状态的任务不可删除");
  }
}

// 删除任务
function delSubTask(row) {
  proxy.$modal
    .confirm("确认删除该任务？")
    .then(function () {
      return delTask(row.id);
    })
    .then(() => {
      proxy.$modal.msgSuccess("删除成功");
      getList();
      getSubList(row.parentId);
    })
    .catch(() => { });
}

// 分配开关
function fenPei(row) {
  num.value = 1;
  queryGroupObj.value = undefined;
  fpId.value.id = row.id;
  fpId.value.parentId = row.parentId;
  fpId.value.taskName = row.taskName;
  fpId.value.createUser = row.createUser;
  openFp.value = true;
}
// 新建分配开关
function fenPeiAdd() {
  queryGroupObj.value = undefined;
  openFp.value = true;
}
// 分配小组
function assignment() {
  groupFp({
    ...queryGroupObj.value,
    groupId: queryGroupObj.value.id,
    id: fpId.value.id,
    parentId: fpId.value.parentId,
  }).then((response) => {
    proxy.$modal.msgSuccess("分配成功");
    openFp.value = false;
    queryGroupObj.value = undefined;
    getList();
    getSubList(fpId.value.parentId);
  });
}
// 分配确认
// function okFp() {
//   if (num.value == 0) {
//     openFp.value = false;
//     queryParamsAdd.value.groupName = queryGroupObj.value.groupName;
//     queryParamsAdd.value.groupLeader = queryGroupObj.value.groupLeader;
//     queryParamsAdd.value.groupId = queryGroupObj.value.id;
//     queryParamsAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
//   } else {
//     assignment();
//   }
// }
function cancelP() {
  openFp.value = false;
  nextTick(() => {
    proxy.$refs["fpRef"].reset();
  });
}
function queryGroup(val) {
  queryGroupObj.value = val;
  if (num.value == 0) {
    openFp.value = false;
    queryParamsAdd.value.groupName = queryGroupObj.value.groupName;
    queryParamsAdd.value.groupLeader = queryGroupObj.value.groupLeader;
    queryParamsAdd.value.groupId = queryGroupObj.value.id;
    queryParamsAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
  } else if (num.value == 2) {
    openFp.value = false;
    queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
    queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
    queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
    queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
  } else {
    assignment();
  }
}
// 打开行政选区
function areaSelect() {
  openArea.value = true;
  resetArea();
}
// 选择关闭后的回调
function closeSelect() {
  openArea.value = false;
  resetArea();
}
function resetArea() {
  selectArea.value = [];
  proxy.resetForm("rulesForm");
}
// 新建任务
function add() {
  proxy.$modal.loading("正在查询，请稍候...");
  districtBoundaryList.value = [];//行政区划经纬度信息
  //查询行政区划经纬度信息
  console.log("查询行政区划经纬度信息", taskDistrictName.value);
  //地图获取行政区划总面积
  //let area = getAllSelectArea(queryParamsAdd.value.parentdistrictList);
  //queryParamsAdd.value.taskArea = area.toString();
  //根据所有省市县全名字符串获取codelist
  let codeList = getCodeByAllName(taskDistrictName.value);
  console.log("查询行政区划codeList");
  console.log(codeList);
  //选择的行政区划数量
  districtCount.value = codeList.length;
  console.log("选择的行政区划数量" + districtCount.value);
  let regionCodes = "";
  for (let i = 0; i < codeList.length; i++) {
    let code = codeList[i];
    if (i > 0) {
      regionCodes += ",";
    }
    regionCodes += code;
  }
  resetAdd();
  queryParamsAdd.value.regionCodes = regionCodes;//地图行政区划code,code字符串
  //查询行政区划经纬度信息
  getDistrictBoundaryByCode(codeList);
  queryGroupObj.value = undefined
  /*//新建任务
  proxy.$refs["rulesForm"].validate((vaild) => {
    if (!vaild) {
      return;
    }
    //resetAdd();
    getTaskNum();
    subTaskData.value = [];
    title.value = "新建任务";
    num.value = 0;
    openAdd.value = true;
    //地图获取行政区划总面积
    let area = getAllSelectArea(queryParamsAdd.value.parentdistrictList);
    queryParamsAdd.value.taskArea = area.toString();
    proxy.$modal.closeLoading();
  });*/
}

// 新建子任务
function addSub(row) {
  numAdd.value = 1;
  resetSubData();
  getSubTaskNum(row.taskNum);
  parentTaskCode.value = row.taskNum;
  parentTaskYear.value = row.taskYear;
  parentTaskId.value = row.id;
  districtListName.value = getProvinces(row.taskDistrict);
  queryParamsAdd.value.parentdistrictList = row.taskDistrict.split('、');
  console.log("新建子任务row:", row);
  subTaskData.value = row.children;
  //任务区域
  queryParamsAdd.value.taskRegion = row.taskRegion;
  if (queryParamsAdd.value.taskRegion.indexOf("MULTIPOLYGON") == -1) {//地图绘制区域
    console.log("地图绘制区域");
  } else {
    console.log("行政区划选择区域");
    //根据所有省市县全名字符串获取codelist
    let codeList = getCodeByAllName(row.taskDistrict);
    console.log("查询行政区划codeList", codeList);
    //选择的行政区划数量
    districtCount.value = codeList.length;
    console.log("选择的行政区划数量" + districtCount.value);
    let regionCodes = "";
    for (let i = 0; i < codeList.length; i++) {
      let code = codeList[i];
      if (i > 0) {
        regionCodes += ",";
      }
      regionCodes += code;
    }
    //父任务行政区划code,code字符串
    queryParamsAdd.value.regionCodes = regionCodes;//地图行政区划code,code字符串
  }
  titleSub.value = "新建子任务";
  num.value = 2;
  openAddSub.value = true;
}

// 新建子任务
function addSub2(row) {
  proxy.$refs["rulesFormAdd"].validate((vaild) => {
    if (!vaild) {
      return;
    }
    resetSubData();
    getSubTaskNum(row.taskNum);
    titleSub.value = "新建子任务";
    num.value = 2;
    openAddSub.value = true;
    parentTaskCode.value = row.taskNum;
    parentTaskYear.value = row.taskYear;
  });
}

// 关联抽样调查点
const relationParams = reactive({
  relationDialog: false,
  relationForm: {
    province: '',
    city: '',
    county: '',
    township: '',
    SurveyPointName: '',
    page: 1,
    rows: 10
  },
  relationTotal: 0,
  relationProvince: [],
  relationCity: [],
  relationCounty: [],
  relationData: [],
  relationLoading: false,
  viewRelationOpen: false
})
let { relationDialog, relationForm, relationTotal,
  relationProvince, relationCity, relationCounty,
  relationData, relationLoading, viewRelationOpen } = toRefs(relationParams)
let ypgId = ref('')
let taskIds = ref('')
let samplingSurveyPointId = ref('')
// 关联抽样调查点
function relationHandle(row) {
  relationDialog.value = true
  ypgId.value = row.id
  samplingSurveyPointId.value = row.samplingSurveyPointId
  getRelationProvince(row.taskDistrict)
}
// 抽样调查点-省、市、区/县
function getRelationProvince(taskDistrict) {
  getCityIdTaskDistrict(taskDistrict).then(res => {
    relationProvince.value = res.data
    let keysArr = Object.keys(relationProvince.value)
    if (keysArr.length > 0) {
      relationForm.value.province = relationProvince.value[keysArr[0]]
      chooseRelationProvince(relationForm.value.province)
      getRelationTable()
    }
  })
}
function chooseRelationProvince(value) {
  relationForm.value.city = '';
  relationForm.value.county = '';
  relationForm.value.province = value;
  relationCity.value = [];
  relationCounty.value = [];
  getChildArea(value).then((response) => {
    relationCity.value = response.data;
  });
}
function chooseRelationCity(value) {
  relationForm.value.county = '';
  relationForm.value.city = value;
  relationCounty.value = [];
  getChildArea(value).then((response) => {
    relationCounty.value = response.data;
  });
}
// 抽样调查点-列表
function getRelationTable() {
  relationLoading.value = true
  // let params = { ...relationForm.value, samplingSurveyPointId: samplingSurveyPointId.value || taskIds.value }
  let params = { ...relationForm.value, samplingSurveyPointId: samplingSurveyPointId.value }
  getSamplingSurveyPoint(params).then(res => {
    let { data, code } = res
    if (code == 200) {
      relationData.value = data.rows
      relationTotal.value = data.total
      data.associatedData && data.associatedData.map(item => {
        let i = relationData.value.findIndex(value => value.id == item.id)
        nextTick(() => {
          i >= 0 && proxy.$refs['relationTable'].toggleRowSelection(relationData.value[i], true)
        })
      })
    }
    relationLoading.value = false
  }).catch(err => {
    relationLoading.value = false
  })
}

// 抽样调查点-查看
let samplingSurveyId = ref('')
function viewRelation(id) {
  viewRelationOpen.value = true
  samplingSurveyId.value = id
}
// 多选
function relationSelectionChange(val) {
  taskIds.value = val.map(item => {
    return item.id
  }).join(',')
}
function getRowKeys(row) {
  return row.id
}
// 关联
function saveRelation() {
  let data = {
    id: ypgId.value,
    samplingSurveyPointId: taskIds.value
  }
  saveSurveySamplingPoint(data).then(res => {
    if (res.code == 200) {
      proxy.$modal.msgSuccess(res.data)
      relationDialog.value = false
      getList()
    }
  })
}
function closeRelation() {
  proxy.resetForm("relationFormRef")
  relationForm.value.page = 1
  taskIds.value = ''
}

/** 查看按钮操作 */
function handleDetil(id) {
  openDetail.value = true;
  detailTask({ id: id }).then((response) => {
    nextTick(() => {
      detilList.preAssessTaskEntity = response.data.preAssessTaskEntity;
      detilList.memberlist = response.data.memberlist;
      detilList.expertlist = response.data.expertlist;
    });
  });
}

// 修改父任务
function updateParentHandle(row) {
  title.value = "修改任务";
  num.value = 0;
  detailTask({ id: row.id }).then((response) => {
    queryParamsAdd.value = {
      ...response.data.preAssessTaskEntity,
      expertlist: response.data.expertlist,
      memberlist: response.data.memberlist,
      geom: '',
    };
    openAdd.value = true;
  });
}

// 修改子任务
function updateSubHandle(row) {
  openAddSub.value = true;
  titleSub.value = "修改子任务";
  num.value = 2;
  parentTaskId.value = row.parentId;
  detailTask({ id: row.id }).then((response) => {
    nextTick(() => {
      queryParamsSubAdd.value = {
        ...response.data.preAssessTaskEntity,
        expertlist: response.data.expertlist,
        memberlist: response.data.memberlist,
        geom: '',
      };
    });
  });
}
// 改变年份
function changeYear(val) {
  getTaskNum(val)
}
// 获取任务编码
function getTaskNum(taskYear) {
  getTaskBian({ taskYear: taskYear }).then((response) => {
    nextTick(() => {
      queryParamsAdd.value.taskNum = response.data;
    });
  });
  return queryParamsAdd.value.taskNum;
}

// 获取子任务编码
function getSubTaskNum(taskNum) {
  getSubTaskBian({ taskNum: taskNum }).then((response) => {
    nextTick(() => {
      queryParamsSubAdd.value.taskNum = response.data;
    });
  });
  return queryParamsAdd.value.taskNum;
}

/** 提交按钮 */
function okAdd() {
  proxy.$refs["rulesFormAdd"].validate((vaild) => {
    if (!vaild) {
      return;
    }
    if (queryGroupObj.value) {
      queryParamsAdd.value.groupName = queryGroupObj.value.groupName;
      queryParamsAdd.value.groupLeader = queryGroupObj.value.groupLeader;
      queryParamsAdd.value.groupId = queryGroupObj.value.id;
      queryParamsAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
    }
    // 新增
    if (title.value == "新建任务") {
      proxy.$modal.loading("正在保存...");
      addTask({ parentTask: queryParamsAdd.value }).then((response) => {
        proxy.$modal.closeLoading();
        openAdd.value = false;
        proxy.$modal.msgSuccess("保存成功");
        if(queryParamsAdd.value.groupName == ''&& getProvinceCodeByAllName(taskDistrictName.value.replace(/,/g, '、')).length > 1 && subTaskData.value.length != getProvinceCodeByAllName(taskDistrictName.value.replace(/,/g, '、')).length){
					ElMessageBox.alert('新建任务为跨省任务，请在新建任务完成后新建子任务，如不需要可忽略此提示。', '消息通知', {
  					  confirmButtonText: '确定',
  					})
				}
        resetAdd();
        getList();
        openArea.value = false;
        form.value.taskDistrict = '';
        //地图传参
        isSaveMapPolygon.value = true;
      }).catch(() => {
        proxy.$modal.closeLoading();
      });
    } else {
      proxy.$modal.loading("正在修改...");
      //截取数据防止报错--仅用于展示不保存
      let subStr = queryParamsAdd.value.taskRegion;
      subStr = subStr.substring(0, 10000);
      queryParamsAdd.value.taskRegion = subStr;
      // 修改
      updateTask(queryParamsAdd.value).then((response) => {
        proxy.$modal.closeLoading();
        openAdd.value = false;
        proxy.$modal.msgSuccess("修改成功");
        resetAdd();
        getList();
      }).catch(() => {
        proxy.$modal.closeLoading();
      });
    }
  });
}
function resetAdd() {
  queryParamsAdd.value.taskYear = "";
  queryParamsAdd.value.taskNum = "";
  queryParamsAdd.value.taskName = "";
  queryParamsAdd.value.taskArea = "";
  queryParamsAdd.value.taskRegion = "";
  queryParamsAdd.value.groupName = "";
  queryParamsAdd.value.groupLeader = "";
  queryParamsAdd.value.groupId = "";
  queryParamsAdd.value.groupLeaderId = "";
  queryParamsAdd.value.memberName = "";
  queryParamsAdd.value.expertName = "";
  queryParamsAdd.value.taskDistrict = "";
  numAdd.value = 2;
  proxy.resetForm("rulesFormAdd");
}
// 取消
function cancelAdd() {
  openAdd.value = false;
  resetAdd();
}

function closeAdd() {
  openAdd.value = false;
  resetAdd();
  openArea.value = false;
  resetArea();
}
/** 提交按钮 */
function okSubAdd() {
  // 新增
  if (titleSub.value == "新建子任务") {
    //获取新建子任务地图区域信息
    getSubTaskMapRegion("okSubAdd");
  } else {
    proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
      if (!vaild) {
        return;
      }
      if (queryGroupObj.value) {
        queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
        queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
        queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
        queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
      }
      //截取数据防止报错--仅用于展示不保存
      let subStr = queryParamsSubAdd.value.taskRegion;
      subStr = subStr.substring(0, 10000);
      queryParamsSubAdd.value.taskRegion = subStr;
      // 修改
      updateTask(queryParamsSubAdd.value).then((response) => {
        openAddSub.value = false;
        proxy.$modal.msgSuccess("修改成功");
        getSubList(parentTaskId.value);
        getList();
        resetSubData();
      });
    });
  }
  /* proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
     if (!vaild) {
       return;
     }
     if (queryGroupObj.value) {
       queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
       queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
       queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
       queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
     }
     // 新增
     if (titleSub.value == "新建子任务") {
       if (numAdd.value == 1) {
         addSubTask({
           ...queryParamsSubAdd.value,
           subdistrictList: [queryParamsSubAdd.value.subdistrictList],
           taskYear: parentTaskYear.value,
           parentTask: parentTaskCode.value,
           parentId: parentTaskId.value,
           parentdistrictList:queryParamsAdd.value.parentdistrictList,
         }).then((response) => {
           openAddSub.value = false;
           proxy.$modal.msgSuccess(response.data.message);
           resetSubData();
           getList();
           queryGroupObj.value = undefined;
           getSubList(parentTaskId.value);
         });
       } else {
         addTask({
           parentTask: queryParamsAdd.value,
           subTask: {
             ...queryParamsSubAdd.value,
             subdistrictList: [queryParamsSubAdd.value.subdistrictList],
             taskYear: parentTaskYear.value,
             parentTask: parentTaskCode.value,
           },
         }).then((response) => {
           proxy.$modal.msgSuccess("保存成功");
           numAdd.value = 1;
           openAddSub.value = false;
           resetSubData();
           getSubList(response.data.parentTaskId);
           queryGroupObj.value = undefined;
           parentTaskId.value = response.data.parentTaskId;
           //地图传参
           isSaveMapPolygon.value = true;
         });
       }
     } else {
       // 修改
       updateTask(queryParamsSubAdd.value).then((response) => {
         openAddSub.value = false;
         proxy.$modal.msgSuccess("修改成功");
         getSubList(parentTaskId.value);
         getList();
         resetSubData();
       });
     }
   });*/
}

function okSubAddNext() {
  //获取新建子任务地图区域信息
  getSubTaskMapRegion("okSubAddNext");
  /*proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
    if (!vaild) {
      return;
    }
    // 新增
    if (queryGroupObj.value) {
      queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
      queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
      queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
      queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
    }
    if (numAdd.value == 1) {
      addSubTask({
        ...queryParamsSubAdd.value,
        subdistrictList: [queryParamsSubAdd.value.subdistrictList],
        taskYear: parentTaskYear.value,
        parentTask: parentTaskCode.value,
        parentId: parentTaskId.value,
        parentdistrictList:queryParamsAdd.value.parentdistrictList,
      }).then((response) => {
        proxy.$modal.msgSuccess("保存成功");
        getSubTaskNum(parentTaskCode.value);
        resetSubData();
        getList();
        queryGroupObj.value = undefined;
        getSubList(parentTaskId.value);
      });
    } else {
      addTask({
        parentTask: queryParamsAdd.value,
        subTask: {
          ...queryParamsSubAdd.value,
          subdistrictList: [queryParamsSubAdd.value.subdistrictList],
          taskYear: parentTaskYear.value,
          parentTask: parentTaskCode.value,
        },
      }).then((response) => {
        proxy.$modal.msgSuccess("保存成功");
        numAdd.value = 1;
        getSubTaskNum(parentTaskCode.value);
        resetSubData();
        // rulesFormSubAdd.value.clearValidate();
        getSubList(response.data.parentTaskId);
        queryGroupObj.value = undefined;
        parentTaskId.value = response.data.parentTaskId;
        //地图传参
        isSaveMapPolygon.value = true;
      });
    }
  });*/
}
function resetSubData() {
  queryParamsSubAdd.value.taskYear = "";
  queryParamsSubAdd.value.taskNum = "";
  queryParamsSubAdd.value.taskName = "";
  queryParamsSubAdd.value.taskArea = "";
  queryParamsSubAdd.value.taskRegion = "";
  queryParamsSubAdd.value.subdistrictList = "";
  (queryParamsSubAdd.value.taskDistrict = ""),
    (queryParamsSubAdd.value.groupName = "");
  queryParamsSubAdd.value.groupLeader = "";
  queryParamsSubAdd.value.groupLeaderId = "";
  queryParamsSubAdd.value.groupId = "";
  proxy.resetForm("rulesFormSubAdd");
}
// 取消新建子任务
function cancelAddSub() {
  openAddSub.value = false;
  getSubList(parentTaskId.value);
}

getYear();
getList();
getProvinceData();
getTreeselect();
</script>
<style scoped lang="scss">
.area span.label {
  text-align: right;
  margin-right: 14px;
  display: inline-block;
  color: #606266;
  font-weight: 700;
  width: 30px;
}
.smallHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #1890ff;
  position: relative;
  color: #fff;
  font-weight: 700;
}

.addTask, .addSubTask {
  width: 700px;
  margin: 0 auto;

  td {
    width: 350px;
  }

  .label {
    text-align: right;
    display: inline-block;
    color: #606266;
    font-weight: 700;
    height: 32px;
    width: 142px;
    padding-right: 14px;
  }
}

h3 {
  color: #333;
  height: 21px;
  font-size: 16px;
  line-height: 21px;
  display: flex;
  align-items: center;
  margin-left: 40px;

  span {
    margin-right: 12px;
    display: inline-block;
    width: 3px;
    height: 16px;
    background: #333;
  }
}
.areaDialog {
  text-align: center;

  .close {
    text-align: right;

    .el-icon {
      color: #606266;
      padding: 20px 0;
      margin-right: 10px;
      right: 0px;
      font-size: 22px;
    }
  }

  width: 320px;
  position: absolute;
  top: 270px;
  left: 320px;
  background: rgba($color: #fff, $alpha: 0.9);
}

//上传面板
.new-uploadDiv {
  position: absolute;
  top: 16px;
  left: 100px;
  width: 358px;
  height: 260px;
  background-color: #fff;
  box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.2);
  border: 1px solid #707070;
  border-radius: 4px;
}

.new-uploadDiv-inner {
  position: absolute;
  top: 20px;
  left: 30px;
  right: 30px;
  bottom: 0px;
}

.new-fileBtn {
  position: absolute;
  top: 50px;
  left: 0px;
  width: 70px;
}

.new-fieldInfoBtn {
  position: absolute;
  top: 70px;
  left: 15px;
  width: 70px;
  color: var(--el-color-primary);
}

.new-filesTextArea {
  position: absolute;
  left: 80px;
  top: 50px;
  right: 0px;
  height: 100px;
}

.new-uploadBtnDiv {
  position: absolute;
  left: 80px;
  right: 0px;
  bottom: 20px;
}

.new-closeBtnDiv {
  position: absolute;
  right: 0px;
  bottom: 20px;
}
:deep(.el-cascader) {
  .el-input{
    min-height: 32px;
  }
}
</style>
